package com.huantai.auth.controller;

import com.huantai.auth.bean.entity.User;
import com.huantai.auth.service.UserService;
import com.huantai.common.consts.LogPatternConst;
import com.huantai.common.controller.BaseRestController;
import com.huantai.common.dto.BaseResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping(value = "/user")
public class UserController extends BaseRestController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "登录")
    @PostMapping(value = "/login")
    public BaseResponse<User> login(
            @Valid @RequestBody User param, BindingResult validResult) {
        if (validResult.hasErrors()) {
            log.info(LogPatternConst.RESPONSE, validResult.toString());
            return this.verifyFailed(validResult);
        }

        User user = userService.getUser(param.getId());
        return succResponse(user);
    }

}
